//
//  HomeAdView.m
//  智慧小区
//
//  Created by lab603 on 15/6/29.
//  Copyright (c) 2015年 Dreamsoul. All rights reserved.
//

#import "HomeAdView.h"
#define adImageH 100
#define padding 10
@implementation HomeAdView
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}
- (void)setAdModel:(NSArray *)adModel{
    _adModel = adModel;
    //添加子控件
    for (int i=0; i<adModel.count; i++) {
        UIImageView *adImageView = [[UIImageView alloc] init];
        adImageView.userInteractionEnabled = YES;
        adImageView.image = adModel[i];
        adImageView.tag = i;
        [adImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(adImageViewDidTap:)]];
        [self addSubview:adImageView];
    }
    //设置子控件的Frame
    for (int i=0; i<self.subviews.count; i++) {
        UIImageView *adImageView = self.subviews[i];
        CGFloat itemX = 0;
        CGFloat itemY = i*adImageH + i*padding;
        adImageView.frame = CGRectMake(itemX, itemY, ScreenWidth, adImageH);
        adImageView.contentMode = UIViewContentModeScaleAspectFill;
        adImageView.clipsToBounds = YES;
    }
}
/**
 *  根据传入的模型，计算视图的Size
 */
+ (CGSize)sizeWithDataArray:(NSArray *)adModel{
    return (CGSize){ScreenWidth,adImageH*adModel.count};
}
- (void)adImageViewDidTap:(UITapGestureRecognizer *)recognizer{
    IWLog(@"%---ld---",recognizer.view.tag);
}
@end
